import React, { Component } from 'react'
import axi from "../axi/axi.js"
export default class edit extends Component {
    state={
        title:"",
        text:"",
        img:"图片",
        name:"小王"
    }
    handChange(e){
        let name=e.target.name
        console.log(name);
        this.setState({
            [name]:e.target.value
        })
    }
   async handClick(){
       let {title,text,img,name}=this.state
        let res=await axi.get("/addlist",{
            params:{
                title,
                text,
                img,
                name
            }
        })  
        console.log(res);
        if(res.data.code==0){
            this.props.history.push("/list")
        }
    }
    render() {
        let {title,text}=this.state
        return (
            <div className="edit">
                <div className="edit-top">
                  标题：  <input type="text" value={title} name="title" onChange={this.handChange.bind(this)} placeholder="输入标题"/>
                </div>
                <div className="edit-content">
                    <textarea value={text} name="text" onChange={this.handChange.bind(this)}></textarea>
                </div>
                <div onClick={this.handClick.bind(this)}>发布</div>
            </div>
        )
    }
}
